<template>
	<view class="content">
		<view class="logo"><image src="../../static/login/logo.png" mode=""></image></view>
		<view class="uni-form-item uni-column">
			<input type="tel" class="uni-input" name="" placeholder="请输入账号"  v-model="userInfo.userPhone"/>
		</view>
		<view class="uni-form-item uni-column">
			<input type="password" class="uni-input" name="" placeholder="请输入密码" v-model="userInfo.userPassword" />
		</view>
		<button type="primary" @click="login">登陆</button>
		<view class="links"><view @tap="gotoLoginByPhone">手机号登陆</view>
		<view>|</view>
		<view class="link-highlight" @tap="gotoRegistration">注册账号</view></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo:{
					userPhone:'',
					userPassword:''
				},
				options:{
					backpage:'',
					backtype:'',
					data:''
				}
			}
		},
		onLoad(options) {
			console.log('跳转参数:',options)
			this.options=options
		},
		methods: {
			gotoRegistration: function () {
				uni.navigateTo({url: 'registration'});
			},
			gotoForgetPassword: function () {
				uni.navigateTo({url: 'forget-password'});
			},
			gotoLoginByPhone: function () {
				uni.navigateTo({url: 'loginByPhone'});
			},
			async login(){
				console.log('登陆信息为:',this.userInfo)
				const res=await this.$myRequest({
					url:'/login',
					method:'POST',
					data:JSON.stringify(this.userInfo)
				})
				//弹窗实体
				uni.showToast({
					title:'登陆成功'
				})
				
				//把登陆信息存入本地
				uni.setStorageSync('user',res.data.data.user)
				uni.setStorageSync('loginToken',res.data.data.loginToken)
				
				//跳转回去
				if(this.options.backtype==1){
					uni.redirectTo({
						url:this.options.backpage+'?data='+this.options.data
					})
				}else{
					uni.switchTab({
						url:this.options.backpage
					})
				}
				
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	$color-primary: #b49950;
	.content{
		padding: 100upx;
	}
	.logo{
	    text-align: center;
		image{
		    height: 200upx;
		    width: 200upx;
		    margin: 0 0 60upx;
		}
	}
	.uni-form-item{
		margin-bottom: 40upx;
		padding: 0;
		border-bottom: 1px solid #e3e3e3;
		.uni-input{
			font-size: 30upx;
			padding: 7px 0;
		}
	}
	button[type="primary"]{
		background-color: $color-primary;
		border-radius: 0;
		font-size: 34upx;
		margin-top: 60upx;
	}
	.links{
		text-align: center;
		margin-top: 40upx;
		font-size: 26upx;
		color: #999;
		view{
			display: inline-block;
			vertical-align: top;
			margin: 0 10upx;
		}
		.link-highlight{
			color: $color-primary
		}
	}
</style>
